package com.example.g3a1.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.base.cons.entity.NoticeBeanItem
import com.example.g3a1.R
import com.example.g3a1.databinding.ItemNoticeBinding

class NoticeAdapter : PagingDataAdapter<NoticeBeanItem, NoticeAdapter.NoticeViewHolder>(diff) {
    companion object{
        val diff = object : ItemCallback<NoticeBeanItem>(){
            override fun areItemsTheSame(
                oldItem: NoticeBeanItem,
                newItem: NoticeBeanItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(
                oldItem: NoticeBeanItem,
                newItem: NoticeBeanItem
            ): Boolean {
                return oldItem.id == newItem.id
            }

        }
    }
    class NoticeViewHolder(view : View) : ViewHolder(view){
        val binding = DataBindingUtil.bind<ItemNoticeBinding>(view)
    }

    override fun onBindViewHolder(holder: NoticeViewHolder, position: Int) {
        holder.binding?.bean = getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoticeViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_notice, parent, false)
        return NoticeViewHolder(view)
    }
}